#include <iostream>
#include <cstdlib>
#include <stack>
using namespace std;

template <typename T>
class CQueue
{
public:
    CQueue(void){}
    ~CQueue(void){}
    
    int size();
    void appendTail(const T & node);
    T deleteHead();

private:
    stack<T> stack1;
    stack<T> stack2;
};

template<typename T>
int CQueue<T>::size()
{
    return stack1.size() + stack2.size();
}

template <typename T>
void CQueue<T>::appendTail(const T & node)
{
    stack1.push(node);
}

template<typename T>
T CQueue<T>::deleteHead()
{
    if (stack2.size() <= 0)
    {
        while (stack1.size() > 0)
        {
            T & data = stack1.top();
            stack1.pop();
            stack2.push(data);
        }
    }

    if (stack2.size() == 0)
    {
        cout << "queue is empty!" << endl;
        exit(0);
    }

    T head = stack2.top();
    stack2.pop();

    return head;
}

int main(int argc, char * argv[])
{
    CQueue<int> queue;
    for (int i = 0; i < 10; ++i)
        queue.appendTail(i);
    
    for(int i = 0; i < 10; ++i)
        cout << queue.deleteHead() << endl;
    cout << queue.size() << endl;
}
